import WatchNumber from '@/utils/WatchNumber';
import { DrawUtilsI } from '../type';
import Visual from '../Visual';

/** 进度控制工具类 */
export default class PositionUtils implements DrawUtilsI {

	/** 可视化控制类 */
	private visual: Visual;

	/** 最大帧数 */
	private max!: WatchNumber;

	/** 当前步骤进度 */
	private speed: number = 0;

	/** 当前步骤的帧进度 */
	private position: number = 0;

	/** 最大帧数 */
	public get Max() {
		return this.max;
	}

	/** 当前步骤进度 */
	public get Speed() {
		return this.speed;
	}

	/** 当前步骤的帧进度 */
	public get Position() {
		return this.position;
	}

	/** 正在加载数据 */
	public get OnLoadingData() {
		return this.position === 0;
	}

	/** 是否结束 */
	public get OnRun() {
		const { speed, position, max, visual } = this;
		const { configUtils } = visual;
		const { valueFrame } = configUtils.config
		return speed * valueFrame.Value + position < max.Value - 1;
	}

	/** 下个步骤 */
	public NextSpeed() {
		this.speed++;
	}

	/**
	 * 构造函数
	 * @param visual 可视化类
	 */
	public constructor(visual: Visual) {
		this.visual = visual;
	}

	/** @override */
	public Load() {
		const { visual } = this;
		const { configUtils, dataUtils } = visual;
		const { valueFrame } = configUtils.config
		const { drawLoadData } = dataUtils;
		const { timeList } = drawLoadData;
		this.max = new WatchNumber((frame) => frame.Value * timeList.length, valueFrame);
		this.speed = 0;
		this.position = 0;
	}

	/** 更新一次 */
	public Update() {
		const { position, visual } = this;
		const { configUtils } = visual;
		const { valueFrame } = configUtils.config
		if (position >= valueFrame.Value - 1) {
			this.position = 0;
		} else {
			this.position++;
		}
	}

	/** @override */
	public LoadingData() { }

	/** @override */
	public BeforeDraw() { }

}
